/*
* ============================================================================
*  Name        : sea_platform_sos.cpp
*  Part of     : Finite state machine framework 
*  Description : 
*  Version     : %version: %
*  
*
* ============================================================================
*/

#include "sea_platform.h"
#include "sea_trace.h"

/**
 * @file sea_platform_sos.cpp
 *
 * @ingroup Platforms
 */
using namespace sea;

TThreadPriority OsThread::m_native_priority[ ] = 
{ 
    EPriorityMuchLess,
    EPriorityLess,
    EPriorityNormal,
    EPriorityMore,
    EPriorityMuchMore
};

// -------------------------------------------------------------------------------------------------
// Trace function
// -------------------------------------------------------------------------------------------------
int Trace::Print( const char* format_str, ... )
{
    static OsMutex traceLock;
    OsMutex::Scoped safe( &traceLock );

    int result = -1;
    char buffer[ MAX_BUFFER ];
    String format = format_str;
    format += "\n";

    va_list arg_list;
    va_start( arg_list, format_str );
    result = vsprintf( buffer, format.c_str( ), arg_list );
    va_end( arg_list );

    RDebug::Printf( buffer );

    return result;
}

// -------------------------------------------------------------------------------------------------
// fopen_s substitude
// -------------------------------------------------------------------------------------------------
int sea::fopen_s( FILE** file, const char *file_name, const char *mode )
{
    if ( file == NULL )
    {
        return -1;
    }

    *file = fopen( file_name, mode );
    if ( *file == NULL )
    {
        return -1;
    }
    return 0;
}
